package ch01.sz;

import java.lang.reflect.Field;

public class AccessPersonFieIds {
    public static void main(String[] args) {
        try{
            Class cls = Class.forName("com.bdqn.Person");
            Object person = cls.newInstance();

            Field address = cls.getDeclaredField("address");
            address.setAccessible(true);
            System.out.println("赋值前的address："+address.get(person));
            address.set(person,"郴州");
            System.out.println("赋值后的address："+address.get(person));
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
    }
}
